#include <stdlib.h>
#include <stdio.h>

#include "list.h"
#include "list.c"

static void print_list(const List *list){
	ListElmt *element;
	char *data;
	int i;

	fprintf(stdout,"List size is %d\n",list_size(list));
	i = 0;
	element = list_head(list);
	while (1){
		data = list_data(element);
		fprintf(stdout,"list[%03d] = %s\n",i,data);
		i++;

		if(list_is_tail(element))
			break;
		else
			element = list_next(element);
	}
	return ;
}

int main(int argc,char **argv){
	List list;
	ListElmt *element;

	char *data;
	int i;
	char c;

	list_init(&list,free);
	element = list_head(&list);
	
	for(;;){
			while((c = getchar()) != EOF){
				if((data = (char *)malloc(sizeof(char))) == NULL)
					return 1;
				data = &c;
				if(list_ins_next(&list,NULL,data) != 0)
					return 1;
				//putchar(*data);
				print_list(&list);
			}
	}

	/*for(i = 10; i > 0; i--){
		if((data = (int *)malloc(sizeof(int))) == NULL)
			return 1;

		*data = i;

		if(list_ins_next(&list,NULL,data) != 0)
			return 1;
		print_list(&list);
	}*/
	
	//print_list(&list);


	return 0;
}
